/*
 * @Author: zuoshentao
 * @Date: 2022-08-26
 * @LastEditors: zuoshentao
 * @LastEditTime: 2022-08-26 17:43:27
 * @Description: 环境变量配置
 * @FilePath: /src/common/envConfig.js
 */

import Request from 'luch-request'
// #ifdef H5
import configH5 from '@/shared/config/h5/config'
// #endif
// #ifdef MP-WEIXIN
import configMP from '@/shared/config/mp-weixin/config'
// #endif

type envConfigParams = {
  BASE_URL: string
  CURRENT_MODE: string
  MODE_CN: string
  CONFIG_PLATFORM: string
  // #ifdef MP-WEIXIN
  AppID?: string
  // #endif
}

let envConfig: envConfigParams

const $zz = {
  http: new Request()
}
// 运行的平台
const RUNTIME_PLATFORM = uni.getSystemInfoSync().uniPlatform
// 当前的环境
const PROCESS_ENV = process.env.NODE_ENV
// 运行的系统
const OS_SYSTEM = uni.getSystemInfoSync().osName

if (RUNTIME_PLATFORM === 'mp-weixin') {
  envConfig = configMP
} else if (RUNTIME_PLATFORM === 'web') {
  envConfig = configH5
}

export default {
  install(app: { $env: object }) {
    app.$env = {
      // 公共参数
      APP_NAME: '',
      VERSION: '1.0.0',
      RUNTIME_PLATFORM,
      OS_SYSTEM,
      PROCESS_ENV,
      // 平台参数
      ...envConfig
    }
    // 挂载http
    uni.$zz = $zz
  }
}
